package org.eclipse.rally.plugin.views;

import java.io.File;
import java.io.FileOutputStream;
import java.util.HashMap;
import java.util.Map;

import javax.swing.JOptionPane;

import org.eclipse.rally.plugin.utils.FileViewer;
import org.eclipse.rally.plugin.utils.RallyConstants;
import org.eclipse.rally.plugin.utils.SWTResourceManager;
import org.eclipse.rally.plugin.utils.UserUtil;
import org.eclipse.rally.plugin.webservice.RallyMain;
import org.eclipse.swt.SWT;
import org.eclipse.swt.browser.Browser;
import org.eclipse.swt.custom.ScrolledComposite;
import org.eclipse.swt.events.MouseAdapter;
import org.eclipse.swt.events.MouseEvent;
import org.eclipse.swt.events.MouseTrackAdapter;
import org.eclipse.swt.graphics.Cursor;
import org.eclipse.swt.graphics.Point;
import org.eclipse.swt.layout.FillLayout;
import org.eclipse.swt.widgets.Composite;
import org.eclipse.swt.widgets.Display;
import org.eclipse.swt.widgets.Event;
import org.eclipse.swt.widgets.Group;
import org.eclipse.swt.widgets.Label;
import org.eclipse.swt.widgets.Link;
import org.eclipse.swt.widgets.Listener;
import org.eclipse.swt.widgets.Shell;
import org.eclipse.swt.widgets.TabFolder;
import org.eclipse.swt.widgets.TabItem;
import com.rallydev.webservice.v1_12.domain.Attachment;
import com.rallydev.webservice.v1_12.domain.AttachmentContent;
import com.rallydev.webservice.v1_12.domain.Defect;
import com.rallydev.webservice.v1_12.domain.HierarchicalRequirement;
import com.rallydev.webservice.v1_12.domain.Task;
import org.eclipse.swt.custom.StyledText;

public class TaskDetailGUI {

	/**
	 * Launch the application.
	 * 
	 * @param args
	 */

	public static Composite composite;
	public static ScrolledComposite scrolledComposite;
	public static Group group;
	public static Map attachmentMap;
	static String strAttachment = "";
	public static Shell shell;
	public static DefectDetailGUI dbg;
	public static String  workProductRefObj = "";
	public static String  pageNameRef = "";
	final Display display = Display.getCurrent();
	final Cursor handCursor = new Cursor(display, SWT.CURSOR_HAND);
	final Cursor waitCursor = new Cursor(display, SWT.CURSOR_WAIT);
	 public static TabItem tabItemRef,tabItemObjRef;
	
	public static void main(String args[]) {
		Display display = new Display();
		shell = new Shell(display);
		shell.setMinimumSize(new Point(400, 1000));
		shell.setLayout(new FillLayout());

		String id = "DE5731";
		TabFolder tabFolder = new TabFolder(shell, SWT.NONE);
		TabItem tabItem = new TabItem(tabFolder, SWT.NONE);
		tabItem.setText("Task &Detail");
		// new TaskDetailGUI().taskDetail(tabFolder, tabItem, id,false);

		shell.setSize(900, 894);
		shell.open();

		while (!shell.isDisposed()) {
			if (!display.readAndDispatch()) {
				display.sleep();
			}
		}

		display.dispose();
	}

	public Group taskDetail(final TabFolder tabFolder, final TabItem tabItem,
			final String taskRefrence, final String pageName) {
		try {
			Task task = (Task) RallyMain.readTaskObject(taskRefrence);
			pageNameRef = pageName;
			tabItemObjRef = tabItem;
			scrolledComposite = new ScrolledComposite(tabFolder, SWT.BORDER
					| SWT.H_SCROLL | SWT.V_SCROLL);
			tabItem.setControl(scrolledComposite);
			scrolledComposite.setExpandHorizontal(true);
			scrolledComposite.setExpandVertical(true);

			composite = new Composite(scrolledComposite, SWT.BORDER);
			composite.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			group = new Group(composite, SWT.BORDER);
			group.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			group.setBounds(10, 10, 860, 899);

			Label lblId = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblId.setBounds(0, 30, 166, 21);
			lblId.setText("ID :");
			lblId.setForeground(SWTResourceManager.getColor(0,
					0, 0));
			lblId.setFont(SWTResourceManager.getFont("Tahoma",
					9, SWT.NORMAL));
			lblId.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

			Label lblName = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblName.setBounds(0, 51, 166, 50);
			lblName.setText("Name:");
			lblName.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblName.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblName.setBackground(SWTResourceManager.getColor(
					216, 228, 248));

			Label lblGeneral = new Label(group, SWT.BORDER);
			lblGeneral.setBounds(0, 10, 168, 21);
			lblGeneral.setText("General");
			lblGeneral.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblGeneral.setFont(SWTResourceManager.getFont(
					"Tahoma", 10, SWT.BOLD));
			lblGeneral.setBackground(SWTResourceManager
					.getColor(122, 150, 223));

			Label lblDescription = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblDescription.setBounds(0, 101, 166, 256);
			lblDescription.setText("Description:");
			lblDescription.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblDescription.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblDescription.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblAttachments = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblAttachments.setBounds(1, 357, 166, 65);
			lblAttachments.setText("Attachments:");
			lblAttachments.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblAttachments.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblAttachments.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblOwner = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblOwner.setBounds(1, 421, 166, 23);
			lblOwner.setText("Owner:");
			lblOwner.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblOwner.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblOwner.setBackground(SWTResourceManager.getColor(
					216, 228, 248));

			Label lblProject = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblProject.setBounds(1, 444, 166, 24);
			lblProject.setText("Project:");
			lblProject.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblProject.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblProject.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblTask = new Label(group, SWT.BORDER);
			lblTask.setBounds(0, 467, 168, 21);
			lblTask.setText("Task");
			lblTask.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblTask.setFont(SWTResourceManager.getFont(
					"Tahoma", 10, SWT.BOLD));
			lblTask.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label lblState = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblState.setBounds(1, 487, 166, 21);
			lblState.setText("State:");
			lblState.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblState.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblState.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_TITLE_INACTIVE_FOREGROUND));

			Label lblEstimate = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblEstimate.setBounds(1, 507, 166, 21);
			lblEstimate.setText("Estimate:");
			lblEstimate.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblEstimate.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblEstimate.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblToDo = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblToDo.setBounds(1, 527, 166, 21);
			lblToDo.setText("To Do:");
			lblToDo.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblToDo.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblToDo.setBackground(SWTResourceManager.getColor(
					216, 228, 248));

			Label lblWorkProduct = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblWorkProduct.setBounds(1, 548, 166, 43);
			lblWorkProduct.setText("Work Product:");
			lblWorkProduct.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblWorkProduct.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblWorkProduct.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblFixedOrCheckedIn = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblFixedOrCheckedIn.setBounds(0, 612, 166, 52);
			lblFixedOrCheckedIn.setText("Fixed / Checked IN:");
			lblFixedOrCheckedIn
					.setForeground(SWTResourceManager.getColor(
							0, 0, 0));
			lblFixedOrCheckedIn.setFont(SWTResourceManager
					.getFont("Tahoma", 9, SWT.NORMAL));
			lblFixedOrCheckedIn
					.setBackground(SWTResourceManager.getColor(
							216, 228, 248));

			Label lblCustom = new Label(group, SWT.BORDER);
			lblCustom.setBounds(0, 591, 166, 21);
			lblCustom.setText("Custom");
			lblCustom.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblCustom.setFont(SWTResourceManager.getFont(
					"Tahoma", 10, SWT.BOLD));
			lblCustom.setBackground(SWTResourceManager
					.getColor(122, 150, 223));

			Label lblNotes = new Label(group, SWT.BORDER);
			lblNotes.setBounds(0, 662, 166, 24);
			lblNotes.setText("Notes");
			lblNotes.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblNotes.setFont(SWTResourceManager.getFont(
					"Tahoma", 10, SWT.BOLD));
			lblNotes.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label lblNotes_1 = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblNotes_1.setBounds(0, 686, 166, 160);
			lblNotes_1.setText("Notes :");
			lblNotes_1.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblNotes_1.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblNotes_1.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			final Label editButton = new Label(group, SWT.NONE);
			editButton.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
			editButton.setImage(SWTResourceManager.getImage(
					TaskDetailGUI.class, "/icons/Button-Edit.gif"));
			editButton.setBounds(727, 10, 40, 19);
			editButton.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseHover(MouseEvent e) {
					System.out.println("entering into mouseHover....");
					final Cursor cursor = new Cursor(Display.getCurrent(),
							SWT.CURSOR_HAND);

					editButton.setCursor(cursor);

				}
			});
			editButton.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					System.out
							.println("entering into addMouseListener..of edit button..");
					composite.dispose();
					group.dispose();

					System.out.println("edit task  button");
					//JOptionPane.showMessageDialog(null, "edit task ", "", 0);
					new EditTaskDetailGUI().editTaskDetail(tabFolder, tabItem,
							taskRefrence,pageName);
				}
			});

			final Label taskBackButton = new Label(group, SWT.NONE);
			taskBackButton.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_TITLE_INACTIVE_BACKGROUND));
			taskBackButton.setImage(SWTResourceManager.getImage(
					TaskDetailGUI.class, "/icons/Back-enabled.gif"));
			taskBackButton.setBounds(791, 10, 49, 20);

			taskBackButton.addMouseTrackListener(new MouseTrackAdapter() {
				@Override
				public void mouseHover(MouseEvent e) {
					System.out.println("entering into mouseHover....");
					final Cursor cursor = new Cursor(Display.getCurrent(),
							SWT.CURSOR_HAND);

					taskBackButton.setCursor(cursor);

				}
			});
			taskBackButton.addMouseListener(new MouseAdapter() {
				@Override
				public void mouseDown(MouseEvent e) {
					//System.out.println("entering into addMouseListener....");
					composite.dispose();
					group.dispose();

					//System.out.println("task  dashboard");
					//JOptionPane.showMessageDialog(null, "task", "", 0);
					//System.out.println("flag**************" + flag);
					if (pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_TASK)) {
						new TaskTabGUI().backToTaskPage(tabFolder);
					} else if(pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_USERSTORIES)) {
						new UserStoryTabGUI().backToUserStoriesPage(tabFolder);
					}else if(pageName != null && pageName.equalsIgnoreCase(RallyConstants.PAGE_DASHBOARD)){
						new DashboardGUI().backToDashboardPage(tabItem,tabFolder);
					}

				}
			});
			Label label4 = new Label(group, SWT.NONE);
			label4.setBounds(167, 10, 683, 20);
			label4.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label lblIdVal = new Label(group, SWT.RIGHT);
			lblIdVal.setBounds(172, 31, 166, 20);
			if (task.getFormattedID() != null) {
				lblIdVal.setText(task.getFormattedID());
			} else {
				lblIdVal.setText("");
			}
			lblIdVal.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			lblIdVal.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblIdVal.setBackground(SWTResourceManager.getColor(
					255, 255, 255));
			lblIdVal.setAlignment(SWT.LEFT);

			StyledText lblNameVal = new StyledText(group, SWT.BORDER
					| SWT.SINGLE);
			// Browser lblNameVal = new Browser(group, SWT.BORDER);
			lblNameVal.setBounds(172, 51, 668, 49);
			if (task.getName() != null)
				lblNameVal.setText(task.getName());
			else
				lblNameVal.setText("");
			lblNameVal.setEditable(false);

			Browser lblDescVal = new Browser(group, SWT.BORDER);
			lblDescVal.setBounds(172, 101, 674, 253);
			if (task.getDescription() != null)
				lblDescVal.setText(task.getDescription());
			else
				lblDescVal.setText("");
			lblDescVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_WIDGET_LIGHT_SHADOW));
			lblDescVal.setEnabled(true);
			lblDescVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblDescVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblDescVal
					.setBackground(SWTResourceManager.getColor(255, 255, 255));

			getAttachment(task);

			Link attachmentLink = new Link(group, SWT.BORDER | SWT.V_SCROLL
					| SWT.H_SCROLL);
			attachmentLink.setText(strAttachment);
			attachmentLink.setBounds(172, 357, 679, 60);
			attachmentLink.addListener(SWT.Selection, new Listener() {
				public void handleEvent(Event event) {
					try {
						String strFileName = event.text;
						AttachmentContent content = (AttachmentContent) attachmentMap
								.get(strFileName);
						byte[] fileBArray = (byte[]) content.getContent();
						FileOutputStream fos = new FileOutputStream(strFileName);
						fos.write(fileBArray);
						fos.close();
						File file = new File(strFileName);
						FileViewer.viewFile(file);
					} catch (Exception r) {
						r.printStackTrace();
					}
				}
			});
			attachmentLink.setForeground(SWTResourceManager
					.getColor(SWT.COLOR_BLACK));
			attachmentLink.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			attachmentLink.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));

			Label lblOwnerVal = new Label(group, SWT.NONE);
			lblOwnerVal.setBounds(172, 420, 289, 21);
			if (task.getOwner() != null && UserUtil.getUsrName(task.getOwner()) != null)
				lblOwnerVal.setText(UserUtil.getUsrName(task.getOwner()));
			else
				lblOwnerVal.setText("");
			lblOwnerVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblOwnerVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblOwnerVal.setBackground(SWTResourceManager
					.getColor(255, 255, 255));
			lblOwnerVal.setAlignment(SWT.LEFT);

			Label lblProjectVal = new Label(group, SWT.NONE);
			lblProjectVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));

			System.out.println("value of the getRefObjectName"
					+ task.getProject().getRefObjectName());

			if (task.getProject() != null
					&& task.getProject().getRefObjectName() != null)
				lblProjectVal.setText(task.getProject().getRefObjectName());
			else
				lblProjectVal.setText("");
			lblProjectVal.setBounds(172, 444, 289, 24);
			lblProjectVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblProjectVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblProjectVal.setBackground(SWTResourceManager.getColor(255, 255,
					255));
			lblProjectVal.setAlignment(SWT.LEFT);

			Label lblStateVal = new Label(group, SWT.NONE);
			lblStateVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getState() != null)
				lblStateVal.setText(task.getState());
			else
				lblStateVal.setText("");
			lblStateVal.setBounds(172, 487, 112, 21);
			lblStateVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblStateVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblStateVal.setBackground(SWTResourceManager
					.getColor(255, 255, 255));
			lblStateVal.setAlignment(SWT.LEFT);

			Label lblEstimateVal = new Label(group, SWT.NONE);
			lblEstimateVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getEstimate() != null)
				lblEstimateVal.setText(String.valueOf(task.getEstimate()));
			else
				lblEstimateVal.setText("");
			lblEstimateVal.setBounds(172, 508, 59, 20);
			lblEstimateVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblEstimateVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblEstimateVal.setBackground(SWTResourceManager.getColor(255, 255,
					255));
			lblEstimateVal.setAlignment(SWT.LEFT);

			Label lblToDoVal = new Label(group, SWT.NONE);
			lblToDoVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getToDo() != null)
				lblToDoVal.setText(String.valueOf(task.getToDo()));
			else
				lblToDoVal.setText("");
			lblToDoVal.setBounds(172, 527, 59, 21);
			lblToDoVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblToDoVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblToDoVal
					.setBackground(SWTResourceManager.getColor(255, 255, 255));
			lblToDoVal.setAlignment(SWT.LEFT);

			final Link workProdLink = new Link(group, SWT.NONE);
			workProdLink.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getWorkProduct() != null
					&& task.getWorkProduct().getRef() != null){
				workProductRefObj = task.getWorkProduct().getRef();
				workProdLink.setText(getWorkProductName(task.getWorkProduct()
						.getRef()));
			}
			else {
				workProdLink.setText("");
			}
			workProdLink.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			workProdLink.setBounds(172, 548, 668, 50);
			workProdLink.addListener(SWT.Selection, new Listener() {
			      public void handleEvent(Event event) {
			    	  workProdLink.setCursor(waitCursor);
			    	  TabItem tabItems[] = tabFolder.getItems();
			    	  System.out.println("tabItem_1"+tabItems[1] +"tabItem_2"+tabItems[2] +"tabItem_3"+tabItems[3]);
			    	  if(workProductRefObj != null && ! "".equals(workProductRefObj)){
			    		  if(event.text != null && event.text.trim().startsWith("DE")){
			    			  workProdLink.setCursor(waitCursor);
			    			  tabItemRef =tabItems[1];
			    			  new DefectDetailGUI().goToDefectDetails(tabFolder,
								  tabItemRef, workProductRefObj, RallyConstants.PAGE_TASK_DETAILS,taskRefrence);
			    			  tabFolder.setSelection(tabItemRef);
			    		  }else if(event.text != null && event.text.trim().startsWith("US")) {
			    			  workProdLink.setCursor(waitCursor);
			    			  tabItemRef =tabItems[2];
			    			  new UserStoryDetailGUI().goToUserStorieDetails(tabFolder, tabItemRef, workProductRefObj, RallyConstants.PAGE_TASK_DETAILS,taskRefrence);      
			    			  tabFolder.setSelection(tabItemRef);
			    			  // JOptionPane.showMessageDialog(null, "edit task ", "", 0);
			    		  
			    		  } else if(event.text != null && event.text.trim().startsWith("TA")){
			    			  JOptionPane.showMessageDialog(null, "Not Implemented ", "", 0);
			    			/*  new TaskDetailGUI().taskDetail(tabFolder,
                                      tabItem, workProductRefObj, RallyConstants.PAGE_TASK_DETAILS);*/
			    			  
			    		  }
			    	  }
			      }
			    });


			Label lblFixedOrCheckInVal = new Label(group, SWT.NONE);
			lblFixedOrCheckInVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getFixedCheckedIN() != null)
				lblFixedOrCheckInVal.setText(task.getFixedCheckedIN());
			else
				lblFixedOrCheckInVal.setText("");
			lblFixedOrCheckInVal.setBounds(172, 612, 679, 52);
			lblFixedOrCheckInVal.setForeground(SWTResourceManager.getColor(0,
					0, 0));
			lblFixedOrCheckInVal.setFont(SWTResourceManager.getFont("Tahoma",
					9, SWT.NORMAL));
			lblFixedOrCheckInVal.setBackground(SWTResourceManager.getColor(255,
					255, 255));
			lblFixedOrCheckInVal.setAlignment(SWT.LEFT);

			Browser lblNotesVal = new Browser(group, SWT.BORDER);
			if (task.getNotes() != null)
				lblNotesVal.setText(task.getNotes());
			else
				lblNotesVal.setText("");
			lblNotesVal.setBounds(172, 686, 679, 160);

			Label lblBlocked = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblBlocked.setBounds(574, 487, 119, 21);
			lblBlocked.setText("Blocked:");
			lblBlocked.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblBlocked.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblBlocked.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblBlockedVal = new Label(group, SWT.NONE);
			lblBlockedVal.setBounds(699, 487, 49, 21);
			if (task.getBlocked() != null)
				lblBlockedVal.setText(String.valueOf(task.getBlocked()));
			else
				lblBlockedVal.setText("");
			lblBlockedVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblBlockedVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblBlockedVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			lblBlockedVal.setAlignment(SWT.LEFT);

			Label lblActuals = new Label(group, SWT.BORDER | SWT.RIGHT);
			lblActuals.setBounds(574, 507, 119, 21);
			lblActuals.setText("Actuals:");
			lblActuals.setForeground(SWTResourceManager
					.getColor(0, 0, 0));
			lblActuals.setFont(SWTResourceManager.getFont(
					"Tahoma", 9, SWT.NORMAL));
			lblActuals.setBackground(SWTResourceManager
					.getColor(216, 228, 248));

			Label lblActualVal = new Label(group, SWT.NONE);
			lblActualVal.setBackground(SWTResourceManager
					.getColor(SWT.COLOR_LIST_BACKGROUND));
			if (task.getActuals() != null)
				lblActualVal.setText(String.valueOf(task.getActuals()));
			else
				lblActualVal.setText("");
			lblActualVal.setBounds(699, 509, 40, 19);
			lblActualVal.setForeground(SWTResourceManager.getColor(0, 0, 0));
			lblActualVal.setFont(SWTResourceManager.getFont("Tahoma", 9,
					SWT.NORMAL));
			lblActualVal.setBackground(SWTResourceManager.getColor(255, 255,
					255));
			lblActualVal.setAlignment(SWT.LEFT);

			if (task.getActuals() != null) {
				Label lblHours = new Label(group, SWT.NONE);
				lblHours.setBounds(745, 509, 49, 19);
				lblHours.setText("Hours");
				lblHours.setBackground(SWTResourceManager
						.getColor(255, 255, 255));
			}
			Label label_21 = new Label(group, SWT.BORDER);
			label_21.setBounds(167, 484, 694, 3);
			label_21.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			label_21.setFont(SWTResourceManager.getFont(
					"Times New Roman", 13, SWT.BOLD));
			label_21.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label label_22 = new Label(group, SWT.BORDER);
			label_22.setBounds(167, 609, 694, 3);
			label_22.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			label_22.setFont(SWTResourceManager.getFont(
					"Times New Roman", 13, SWT.BOLD));
			label_22.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label label_23 = new Label(group, SWT.BORDER);
			label_23.setBounds(167, 683, 694, 3);
			label_23.setForeground(SWTResourceManager.getColor(
					0, 0, 0));
			label_23.setFont(SWTResourceManager.getFont(
					"Times New Roman", 13, SWT.BOLD));
			label_23.setBackground(SWTResourceManager.getColor(
					122, 150, 223));

			Label label = new Label(group, SWT.SEPARATOR);
			label.setBounds(166, 30, 2, 867);
			label.setForeground(SWTResourceManager.getColor(49,
					106, 197));
			label.setBackground(SWTResourceManager.getColor(49,
					106, 197));

			if (task.getToDo() != null) {
				Label label_1 = new Label(group, SWT.NONE);
				label_1.setBounds(237, 527, 49, 19);
				label_1.setText("Hours");
				label_1.setBackground(SWTResourceManager
						.getColor(255, 255, 255));
			}

			if (task.getEstimate() != null) {
				Label label_2 = new Label(group, SWT.NONE);
				label_2.setBounds(235, 507, 49, 19);
				label_2.setText("Hours");
				label_2.setBackground(SWTResourceManager
						.getColor(255, 255, 255));
			}

			scrolledComposite.setContent(composite);
			scrolledComposite.setMinSize(composite.computeSize(SWT.DEFAULT,
					SWT.DEFAULT));

		} catch (Exception e) {
			e.printStackTrace();
		}

		return group;
	}

	public static void getAttachment(Task task) {

		attachmentMap = new HashMap();
		strAttachment = "";
		if (task.getAttachments() != null) {
			Attachment[] attachment = task.getAttachments();
			for (Object obj : attachment) {
				Attachment attach = (Attachment) obj;
				attach = (Attachment) RallyMain.readAttachemntObject(attach
						.getRef());
				AttachmentContent content = (AttachmentContent) RallyMain
						.readAttachemntContentObject(attach.getContent()
								.getRef());
				System.out.println(attach.getName() + "----"
						+ content.getContent() + "--"
						+ attach.getContent().getType());
				attachmentMap.put(attach.getName(), content);
				strAttachment += "<A>" + attach.getName() + "</A> \n";
			}

		}
	}

	public static String getWorkProductName(String objRef) {
		String workProdName = "";
		String[] strTokens = null;
		if (objRef != null) {
			strTokens = objRef.split("/");

			for (int i = 0; i < strTokens.length; i++) {
				if (strTokens[i].equalsIgnoreCase("hierarchicalrequirement")) {
					HierarchicalRequirement hr = (HierarchicalRequirement) RallyMain
							.readTaskWorkProdObject(objRef);
					workProdName += "<A>" + hr.getFormattedID() + ":" + " "
							+ hr.getName() + "</A> \n";

					break;
				} else if (strTokens[i].equalsIgnoreCase("defect")) {
					Defect defect = (Defect) RallyMain.readDefectObject(objRef);
					workProdName += "<A>" + defect.getFormattedID() + ":" + " "
							+ defect.getName() + "</A> \n";

					break;
				} else if (strTokens[i].equalsIgnoreCase("task")) {
					Task task = (Task) RallyMain.readTaskObject(objRef);
					workProdName += "<A>" + task.getFormattedID() + ":" + " "
							+ task.getName() + "</A> \n";
					break;
				}

			}
		}

		return workProdName;
	}
	
	public void backToTaskDetailPage(TabFolder tabFolder, TabItem tabItem,
			String taskRefrence, String pageName) {
		
		if(pageName.equalsIgnoreCase(RallyConstants.PAGE_TASK_DETAILS)){
			taskDetail(tabFolder, tabItemObjRef, taskRefrence, pageNameRef);
			tabFolder.setSelection(tabItemObjRef);
		}
		 else{ 
			taskDetail(tabFolder, tabItem, taskRefrence, pageName);
		 }
		
	}
	
}